//
//  UserInfoTableViewCell.m
//  HJZWeiBo
//
//  Created by 蒋晨成 on 16/5/28.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "UserInfoTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "NSString+Font.h"


@implementation UserInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 60, 60)];
        self.iconImageView.layer.cornerRadius = 30;
        self.iconImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_iconImageView];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 10, 0, 30)];
        [self.contentView addSubview:_nameLabel];
        
        self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 40, 200, 20)];
        self.descriptionLabel.textColor = [UIColor grayColor];
        self.descriptionLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_descriptionLabel];
        
        
    }
    return self;
}

-(void)setUser:(WeiboUser *)user {
    _user = user;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:user.avatarHDUrl]];
    [self setNameLabelTextWithString:user.name];
    [self setDescriptionLabelTextWithString:user.userDescription];
    
}
- (void)setNameLabelTextWithString:(NSString *)string {
    CGRect newFrame = _nameLabel.frame;
    newFrame.size.width = [string getTextWidthWithFont:[UIFont systemFontOfSize:17] height:30];
    _nameLabel.frame = newFrame;
    _nameLabel.text = string;
}

- (void)setDescriptionLabelTextWithString:(NSString *)string {
    _descriptionLabel.text = [NSString stringWithFormat:@"简介：%@",string];
}

@end
